package entity

import (
	"shqsoft.cn/pasnj/base"

	"github.com/jinzhu/gorm"
)

//DGCKLRTZ DGCKLRTZ
type DGCKLRTZ struct {
	ID           int          `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	DTID         string       `gorm:"column:DTID"`
	EMID         int          `gorm:"column:EMID"`
	UTID         int          `gorm:"column:UTID"`
	Organization Organization `gorm:"ForeignKey:UTID"`
	EMNO         string       `gorm:"column:EMNO"`
	EMNM         string       `gorm:"column:EMNM"`
	TZLX         int          `gorm:"column:TZLX"`
	TZLXCaption  string       `gorm:"-"`
	TZJE         float64      `gorm:"column:TZJE"`
}

//TableName TableName
func (DGCKLRTZ) TableName() string {
	return "T_COMP_JHCW_FYKH_DGLR_TZ"
}

// AfterFind AfterFind
func (u *DGCKLRTZ) AfterFind() (err error) {
	if u.TZLX == 1 {
		u.TZLXCaption = "纯存款基数"
	} else if u.TZLX == 2 {
		u.TZLXCaption = "派生存款基数"
	} else if u.TZLX == 3 {
		u.TZLXCaption = "纯存款业绩"
	} else if u.TZLX == 4 {
		u.TZLXCaption = "派生存款业绩"
	} else if u.TZLX == 5 {
		u.TZLXCaption = "纯存款理财业绩"
	} else if u.TZLX == 6 {
		u.TZLXCaption = "派生存款理财业绩"
	}
	return
}

//AfterCreate 插入前的触发器
func (u *DGCKLRTZ) AfterCreate(tx *gorm.DB) (err error) {
	err = tx.Exec("EXEC UP_COMP_JHCW_FYKH_DGLR_TZ ?", u.DTID).Error
	if err != nil {
		return err
	}
	return
}

// AfterUpdate 默认员工不允许,有认定关系，不允许更改部门
func (u *DGCKLRTZ) AfterUpdate(tx *gorm.DB) (err error) {
	err = tx.Exec("EXEC UP_COMP_JHCW_FYKH_DGLR_TZ ?", u.DTID).Error
	if err != nil {
		return err
	}
	return
}

//DGCKLRTZEF DGCKLRTZEF
func DGCKLRTZEF() base.EntityFunc {
	return func() interface{} {
		entity := DGCKLRTZ{}
		return &entity
	}
}

//DGCKLRTZESF DGCKLRTZESF
func DGCKLRTZESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []DGCKLRTZ
		return &entities
	}
}

func init() {
	relationship := []string{"Organization"}
	base.DaoPoolObj.Put("DGCKLRTZ", base.NewDefaultDao(DGCKLRTZEF(), DGCKLRTZESF(), relationship))
}
